package com.shenmazong.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shenmazong.entity.TbCollect;
import com.shenmazong.mapper.TbCollectMapper;
import com.shenmazong.service.TbCollectService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shenmazong.utils.ResultResponse;
import com.shenmazong.vo.ListParamVo;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * 用户收藏文章表 ——> John 服务实现类
 * </p>
 *
 * @author 还怕大雨吗
 * @since 2021-09-18
 */
@Service
public class TbCollectServiceImpl extends ServiceImpl<TbCollectMapper, TbCollect> implements TbCollectService {

    @Resource
    private TbCollectMapper tbCollectMapper;


    /***
     * @description 查询某个用户的收藏，根据个人id
     * @params [listParamVo]
     * @return com.shenmazong.utils.ResultResponse
     * @author -还怕大雨吗
     * @date 2021/9/18 13:56
     */
    @Override
    @Cacheable(value = "selectCollect")
    public ResultResponse selectCollect(ListParamVo listParamVo) {
//        Page<TbCollect> tbCollectPage = tbCollectMapper.selectPage(
//                new Page<TbCollect>(listParamVo.getCurrent(), listParamVo.getSize()), null
//        );
        IPage<TbCollect> tbCollectIPage = tbCollectMapper.selectCollectPage(
                new Page<TbCollect>(listParamVo.getCurrent(), listParamVo.getSize()),
                 listParamVo.getParamMap().get("issuedId")
        );
        return ResultResponse.SUCCESS(tbCollectIPage);
    }

    /**
     * @description 添加文章到我的收藏
     * @params [listParamVo]
     * @return com.shenmazong.utils.ResultResponse
     * @author -还怕大雨吗
     * @date 2021/9/18 13:56
     */
    @Override
    @CacheEvict(value = "selectCollect",allEntries = true)
    public ResultResponse insertCollect(TbCollect listParamVo) {
        try {
            tbCollectMapper.insert(listParamVo);
        } catch (Exception e) {
            return ResultResponse.FAILED();
        }
        return ResultResponse.SUCCESS();
    }

    /***
     * @description 从我的收藏里删除某一个
     * @params [listParamVo]
     * @return com.shenmazong.utils.ResultResponse
     * @author -还怕大雨吗
     * @date 2021/9/18 13:57
     */
    @Override
    @CacheEvict(value = "selectCollect",allEntries = true)
    public ResultResponse deleteCollect(Long listParamVo) {
        tbCollectMapper.deleteById(listParamVo);
        return ResultResponse.SUCCESS();
    }

    /***
     * @description 修改我的收藏
     * @params [listParamVo]
     * @return com.shenmazong.utils.ResultResponse
     * @author -还怕大雨吗
     * @date 2021/9/18 13:57
     */
    @Override
    @CacheEvict(value = "selectCollect",allEntries = true)
    public ResultResponse updateCollect(TbCollect listParamVo) {

        return null;
    }
}
